package com.hdax.dmw.order.listener;

import com.hdax.dmw.entity.order.TxMsg;
import com.hdax.dmw.order.service.TxMsgService;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class TxConfirmCallback implements RabbitTemplate.ConfirmCallback {

    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Autowired
    private TxMsgService txMsgService;

    @PostConstruct
    public void init(){
        rabbitTemplate.setConfirmCallback(this);
    }

    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        //mq确认收到消息，
        //修改本地消息表，0--》1
        String orderNo = correlationData.getId();
        TxMsg txMsg = txMsgService.getById(orderNo);
        txMsg.setVersion(txMsg.getVersion()+1);
        txMsg.setMsg_result("1");
        txMsgService.updateById(txMsg);
    }
}
